Repository navigation
DEV-1070: decode a GSR code below the reference as open, and nudge GSR - #19
Merged
Merged
Conversation
The GSR amplifier equation, R = Rf / (V/Vref - 1), has no positive solution at or below the amplifier's 0.5 V reference. No skin resistance can pull the output under it, so a code there means the electrodes are open. GSRSensor has long raised a range-3 code below 683 to 683, but ranges 0-2 did not, and in auto-range they see these codes too. When the electrodes come off, the device climbs one range at a time, and the firmware repeats the sample that triggered each switch through the 80 ms settling time, tagged with the range it was measured on. The equation gave them a negative resistance, and the conductance was then reported as 0. calibrateGsrDataToResistanceWithOpenCircuitLimit now decodes any code below 683 as range 3 at 683, on every range, and absorbs the old range-3 clamp. An open circuit reads the same on every range as the settled range 3 does: 4.5 GOhm, 0.0002 uS. This is the rule the Java driver, the C# API, the web SDK and ASM_BaseStation get under the same ticket. NudgeGsrResistance was never called. processData now calls it as the full nudge, as in the Java driver: a fixed range clamps to its own window, and auto-range is floored at 8 kOhm (ASM-2156). No code decodes below 8 kOhm now, so in auto-range the floor is only a backstop. On a fixed range, an open circuit reads the top of its window. The nudge used to index its window table with any setting other than 4, so it would have trapped on -1, the value before the InfoMem is read, and on 5-7 from the 3-bit mask. Those now pass through, and nothing is decoded for them, as before. SensorTest gains four tests: below-reference codes read open on every range in auto-range; fixed ranges clamp to their window; codes from the limit up decode as before; and an unset or invalid range passes through. Not built or run: there is no Swift toolchain on the Windows machine this was written on. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Sep 26, 2026
JongChern
approved these changes
Oct 2, 2026
JongChern
left a comment
Contributor
There was a problem hiding this comment.
Approving. The decode now follows the same rules as the Java driver and the C# API: a code below 683 reads as open on every range, auto-range is only floored at 8 kOhm, and a fixed range clamps to its window. The bounds check in NudgeGsrResistance matters now that it's called, because it would otherwise crash on a setting of -1 or 5-7. All four new tests ran and passed on the macOS run at fb027ae.
None of these block the merge:
- Wiring in the nudge is the only change here that affects readings taken with skin contact, but no test checks that a normal reading inside a fixed range's window passes through unchanged. I'd add one, either here or as a quick follow-up.
testGSRCodesFromTheLimitUpDecodeAsBeforechecks 7 sample codes in auto-range. Looping over every code from 683 to 4095 on every range is cheap, as the Java and C# tests do, and the same loop could cover the fixed ranges for point 1.- Nothing asserts on the conductance channel. A check that an open circuit reads about 0.0002 uS would cover the
> 0guard. - A pre-existing nit, worth fixing while you're here: line 65 prints
GSR (kOhms)on every sample, which floods the console of any app using the library. - The description says Shimmer3 only, but
Shimmer3Protocoluses thisGSRSensorfor Shimmer3R too. The values are the same for both, so the change is right for 3R as well.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DEV-1070
Explainer: before/after charts for DEV-1067, DEV-1068 and DEV-1070, and a table of the sibling PRs across every host API: https://claude.ai/artifact/6hDc2Ue9hdF8gcUDZXzFts (Shimmer sign-in)
Problem
The GSR amplifier equation,
R = Rf / (V/Vref − 1), has no positive solution at or below the amplifier's 0.5 V reference. No skin resistance can pull the output under it, so a code there means the electrodes are open.GSRSensorhas long raised a range-3 code below 683 to 683, but ranges 0–2 did not, and in auto-range they see these codes too. When the electrodes come off, the device climbs one range at a time, and the firmware repeats the sample that triggered each switch through the 80 ms settling time, tagged with the range it was measured on. The equation gave them a negative resistance, and the conductance was then reported as 0.Separately,
NudgeGsrResistancewas never called, so fixed ranges were never clamped to their window.Fix
calibrateGsrDataToResistanceWithOpenCircuitLimitdecodes any code below 683 as range 3 at 683, on every range, and absorbs the old range-3 clamp. An open circuit reads the same on every range as the settled range 3 does: 4.5 GΩ, 0.0002 µS. This is the rule the Java driver, the C# API, the web SDK and ASM_BaseStation get under the same ticket.processDatanow callsNudgeGsrResistanceas the full nudge, as in the Java driver: a fixed range clamps to its own window, and auto-range is floored at 8 kΩ (ASM-2156). No code decodes below 8 kΩ now, so in auto-range the floor is only a backstop. On a fixed range, an open circuit reads the top of its window.Tests
SensorTestgains four tests:Sibling PRs (same rule, same ticket)
🤖 Generated with Claude Code